package com.sec.android.app.myfiles.module.local.recent;

import java.util.ArrayList;

import android.app.FragmentManager;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;

import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.AbsFileOperationImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.operation.FileOperationArgs;
import com.sec.android.app.myfiles.operation.FileOperationException;
import com.sec.android.app.myfiles.operation.FileOperator;
import com.sec.android.app.myfiles.operation.FileOperator.Operation;
import com.sec.android.app.myfiles.operation.ProgressListener;
import com.sec.android.app.myfiles.provider.DbTableInfo;

public class RecentOperationImp extends AbsFileOperationImp {

    public RecentOperationImp(Context context, ProgressListener listener) {
        super(context, listener);
    }

    @Override
    protected void makeScanLists(Operation op, ArrayList<String> pathList, ArrayList<String> fileList, FileOperationArgs args, int handledCount) {
    }

    @Override
    protected boolean isSupport(FileRecord record) {
        return record.getStorageType() == FileRecord.StorageType.Recent;
    }

    @Override
    protected boolean isSupportCopyMove(FileRecord src, FileRecord dst) {
        // NOT USE
        return false;
    }

    @Override
    protected boolean _copy(FileRecord src, FileRecord dst) throws FileOperationException {
        // NOT USE
        return false;
    }

    @Override
    protected boolean _copy(ArrayList<FileRecord> src, FileRecord dst, FragmentManager fragmentManager, boolean singleFile, boolean dupCheck,
                            FileOperator operator) throws FileOperationException {
        return false;
    }

    @Override
    protected boolean _move(FileRecord src, FileRecord dst) throws FileOperationException {
        // NOT USE
        return false;
    }

    @Override
    protected boolean _move(ArrayList<FileRecord> src, FileRecord dst, FragmentManager fragmentManager, boolean singleFile, FileOperator operator, ArrayList<FileRecord> handledSrcList)
            throws FileOperationException {
        return false;
    }

    @Override
    protected boolean _rename(FileRecord src, FileRecord dst) throws FileOperationException {
        // NOT USE
        return false;
    }

    @Override
    protected boolean _delete(FileRecord record) {
        boolean ret = false;
        ContentResolver cr = mContext.getContentResolver();
        try {
            DbTableInfo tableInfo = DbTableInfo.getInstance(FileRecord.StorageType.Recent);
            if (tableInfo != null) {
                Uri uri = Uri.parse(tableInfo.getUri());
                StringBuilder selection = new StringBuilder();
                selection.append(tableInfo.getColumnName(DbTableInfo.COLUMN_ID.PATH)).append("=? AND ")
                        .append(tableInfo.getColumnName(DbTableInfo.COLUMN_ID.NAME)).append("=?");
                String[] selectionArgs = new String[]{
                        record.getPath(), record.getName()};
                if (cr.delete(uri, selection.toString(), selectionArgs) > 0) {
                    // deleteRecentItemThumbCache(context, filePath);
                    ret = true;
                }
            }
        } catch (Exception e) {
            Log.e(this, "Exception:" + e.toString());
        }
        return ret;
    }

    @Override
    protected FileRecord _mkdir(FileRecord dst, String name) {
        // NOT USE
        return null;
    }

    @Override
    protected FileRecord _getUniqueFileRecord(FileRecord record) {
        return null;
    }

    @Override
    protected ArrayList<FileRecord> _getListInDirectory(FileRecord record) {
        return null;
    }

    @Override
    protected void _preOperation(Operation operationType) {
    }

    @Override
    protected void _postOperation(Operation operationType, FileOperationArgs args, int handledCount) {
    }

    @Override
    protected boolean isSupportRecursiveCopyMove() {
        return false;
    }
}
